package com.zqh.apiproductcommentcud.controller;

import com.zqh.apiproductcommentcud.redis.RedisUtil;
import com.zqh.myfmmall.clients.OrderUDClient;
import com.zqh.myfmmall.clients.ProductCommentCUDClient;
import com.zqh.myfmmall.result.Result;
import com.zqh.myfmmall.rowbeans.entity.Orders;
import com.zqh.myfmmall.rowbeans.entity.ProductComments;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2022-03-05 23:00
 */
@RestController
@RequestMapping("productComment/cud")

public class ApiProductCommentCUDController{
    /**
     * 服务对象
     */
    @Autowired
    private ProductCommentCUDClient productCommentCUDClient;
    @Autowired
    private HttpServletRequest httpServletRequest;
    @Autowired
    private RedisUtil redisUtil;


    @PostMapping("create")
    Result create(@RequestBody ProductComments productComment){
        String token = httpServletRequest.getHeader("token");
        String userId = (String) redisUtil.get(token);
        productComment.setUserId(userId);
        //摄制回复状态为未回复
        productComment.setReplyStatus(0);
        return productCommentCUDClient.create(productComment);
    }

    /*@PutMapping("update")
    Result update(@RequestBody ProductComments productComments){

    }*/

    @DeleteMapping("delete/{id}")
    Result delete(@PathVariable("id") String id){
        return productCommentCUDClient.delete(id);
    }

}
